<template>
    <div class="content">
        <VueUeditorWrap
            id="uedtior"
            v-model="content"
            :config="editorConfig"
            :editorDependencies="['ueditor.config.js', 'ueditor.all.js']"
            style="height: 100%"
            :destroy="true"
            @ready="editorReady"
        />
    </div>
</template>

<script>
import axios from "axios";
import VueUeditorWrap from "vue-ueditor-wrap";
export default {
    name: "UEditor",
    components: { VueUeditorWrap },
    props: {
        value: {
            default: "",
        },
    },
    data() {
        return {
            content: "",
            editorConfig: {
                UEDITOR_HOME_URL: "/ueditor/",
                zIndex: 1,
                initialFrameWidth: null,
                serverUrl: `${$A.apiUrl("system/ueupload")}?token=${$A.getToken()}`,
                autoHeightEnabled: false,
                iframeUrlMap: {
                    anchor: "/ueditor/dialogs/anchor/anchor.html?20220503",
                    insertimage: "/ueditor/dialogs/image/image.html?20220503",
                    link: "/ueditor/dialogs/link/link.html?20220503",
                    spechars: "/ueditor/dialogs/spechars/spechars.html?20220503",
                    searchreplace:
                        "/ueditor/dialogs/searchreplace/searchreplace.html?20220503",
                    insertvideo: "/ueditor/dialogs/video/video.html?20220503",
                    help: "/ueditor/dialogs/help/help.html?20220503",
                    preview: "/ueditor/dialogs/preview/preview.html?20220503",
                    emotion: "/ueditor/dialogs/emotion/emotion.html?20220503",
                    wordimage: "/ueditor/dialogs/wordimage/wordimage.html?20220503",
                    attachment: "/ueditor/dialogs/attachment/attachment.html?20220503",
                    insertframe:
                        "/ueditor/dialogs/insertframe/insertframe.html?20220503",
                    edittip: "/ueditor/dialogs/table/edittip.html?20220503",
                    edittable: "/ueditor/dialogs/table/edittable.html?20220503",
                    edittd: "/ueditor/dialogs/table/edittd.html?20220503",
                    scrawl: "/ueditor/dialogs/scrawl/scrawl.html?20220503",
                    template: "/ueditor/dialogs/template/template.html?20220503",
                    background: "/ueditor/dialogs/background/background.html?20220503",
                },
            },
        };
    },
    methods: {
        editorReady(editor) {
            const all = document.getElementById('uedtior').scrollHeight
            const toolbar = document.getElementsByClassName('edui-editor-toolbarbox')[0].scrollHeight
            const statusbar = document.getElementsByClassName('edui-editor-bottomContainer')[0].scrollHeight
            editor.setHeight(all - toolbar - statusbar)
        }
    },
    mounted() {
        this.content = this.value;
    },
    watch: {
        content(newValue) {
            this.$emit('input', newValue);
        }
    },
};
</script>
